home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / language / embedded / 68hc11 / smallc11.arc / CC41.C < prev    next >
Text File  |  1988-07-01  |  5KB  |  305 lines

  1. /********************************************************
  2. *    placed in SCCS file    Oct 29 86    Jrd    *
  3. *    File = cc41.c                    *
  4. ********************************************************/
  5.  
  6. #include <dos.h>
  7.  
  8. /*** print all assembler info before any code is generated*/
  9.  
  10. header()
  11. {
  12. struct date d;
  13. struct time t;
  14.  
  15. getdate(&d);    /* MS-DOS / Turbo-C dependant !!!! */
  16. gettime(&t);
  17.  
  18. printf("\n*******************************************************************\n");
  19. printf("* SMALL-C Compiler V2.0.2                               Feb 15 1987\n");
  20. printf("* Copyright 1982 J. E. Hendrix                                     \n");
  21. printf("* Modified by Motorola for 68HC11                                  \n");
  22. printf("* Modified by HCS to compile Compiler with Turbo-C 1.5             \n");
  23. printf("* Compiler compiled on: %s, %s\n*\n",__DATE__,__TIME__);
  24. printf("* 68HC11 Cross-Compile done on: %2.2d/%2.2d/%4d  %2.2d:%2.2d:%2.2d\n",d.da_mon,d.da_day,d.da_year,t.ti_hour,t.ti_min,t.ti_sec);
  25. printf("*\n");
  26. printf("*******************************************************************\n");
  27. printf("*\n");
  28. beglab=getlabel();
  29. }
  30.  
  31. /*** print any assembler stuff needed at the end*/
  32. trailer()  {
  33.  
  34.     extern int reperr;
  35.     if(reperr == YES)
  36.     {
  37.         fprintf(stderr,"\n**** Errors in compile ****\n");
  38.         exit(-1);
  39.     }
  40.     else
  41.     {
  42.         fprintf(stderr,"\n**** NO Errors in compile ****\n");
  43.     }
  44. }
  45.  
  46. /*** declare entry point*/
  47. xentry() {
  48.   outstr(ssname);
  49.   ot("equ *");
  50.   nl();
  51.   }
  52.  
  53. /*
  54. ** declare external reference
  55. */
  56. external(name) char *name; {
  57. /*
  58. ot("xref ");
  59. outstr(name);
  60. nl();
  61.     */
  62. }
  63.  
  64. /*
  65. ** fetch object indirect to primary register
  66. */
  67. indirect(lval) int lval[]; {
  68. if(lval[1]==CCHAR)
  69.     {
  70.     ol("xgdx");
  71.     ol("clra");
  72.     ol("ldab 0,x");
  73.     }
  74. else    {
  75.     ol("xgdx");
  76.     ol("ldd 0,x");
  77.     }
  78. }
  79.  
  80. /*
  81. ** fetch a static memory cell into primary register
  82. */
  83. getmem(lval)  int lval[];
  84. {
  85.   char *sym;
  86.   sym=lval[0];
  87.   if((sym[IDENT]!=POINTER)&(sym[TYPE]==CCHAR))
  88.   {
  89.     ol("clra");
  90.     ot("ldab ");
  91.   }
  92.   else
  93.   {
  94.     ot("ldd ");
  95.   }
  96.   outstr(sym+NAME);
  97.   nl();
  98. }
  99.  
  100. /*
  101. ** fetch addr of the specified symbol into primary register
  102. */
  103. getloc(sym)  char *sym; {
  104.   const1(getint(sym+OFFSET, OFFSIZE)-csp);
  105. ol("tsx");
  106. ol("pshx");
  107. ol("tsx");
  108. ol("addd 0,x");
  109. ol("pulx");
  110. }
  111.  
  112. /*
  113. ** store primary register into static cell
  114. */
  115. putmem(lval)  int lval[]; {
  116.   char *sym;
  117.   sym=lval[0];
  118.   if((sym[IDENT]!=POINTER)&(sym[TYPE]==CCHAR)) {
  119.     ot("stab ");
  120.     }
  121.   else ot("std ");
  122.   outstr(sym+NAME);
  123.   nl();
  124.   }
  125.  
  126. /*
  127. ** put on the stack the type object in primary register
  128. */
  129. putstk(lval) int lval[]; {
  130. if(lval[1]==CCHAR) {
  131.     ol("stab 0,x");
  132.     }
  133.   else ol("std 0,x");
  134.   }
  135.  
  136. /*
  137. ** move primary register to secondary
  138. */
  139. move() {
  140. ol("pshb");
  141. ol("psha");
  142. ol("pulx");
  143.   }
  144.  
  145. /*
  146. ** swap primary and secondary registers
  147. */
  148. swap() {
  149. ol("xgdx");
  150.   }
  151.  
  152. /*** partial instruction to get immediate value
  153. ** into the primary register*/
  154. immed() {
  155.   ot("ldd #");
  156.   }
  157.  
  158. /*
  159. ** partial instruction to get immediate operand
  160. ** into secondary register
  161. */
  162. immed2() {
  163.   ot("ldx #");
  164.   }
  165.  
  166. /*** push primary register onto stack*/
  167. push() {
  168. ol("pshb");                  /* push registers */
  169. ol("psha");
  170.   csp=csp-BPW;
  171.   }
  172.  
  173. /*** unpush or pop as required*/
  174. smartpop(lval, start) int lval[]; char *start;
  175. {
  176. pop();
  177. /*if(lval[5])  pop();
  178.   else unpush(start);
  179.     */
  180.   }
  181.  
  182.  
  183. /*** pop stack to the secondary register*/
  184. pop() {
  185.   ol("pulx");
  186.   csp=csp+BPW;
  187.   }
  188.  
  189. /*** swap primary register and stack*/
  190. swapstk() {
  191. ol("puly");
  192. ol("xgdy");
  193. ol("pshy");
  194.   }
  195.  
  196. /*** process switch statement*/
  197. sw() {
  198. call("ccswit");
  199.   }
  200.  
  201. /*** call specified subroutine name*/
  202. call(sname)  char *sname; {
  203.   ot("jsr ");
  204.   outstr(sname);
  205.   nl();
  206.   }
  207.  
  208. /*** return from subroutine*/
  209. ret() {
  210.   ol("rts");
  211.   }
  212.  
  213. /*** perform subroutine call to value on stack*/
  214. callstk() {
  215. ol("pulx");
  216. ol("jsr 0,x");
  217.   csp=csp+BPW;
  218.   }
  219.  
  220. /*** jump to internal label number*/
  221. jump(label)  int label; {
  222.   ot("jmp ");
  223.   printlabel(label);
  224.   nl();
  225.   }
  226.  
  227. /*** test primary register and jump if false*/
  228. testjump(label)  int label; {
  229.   ol("cmpd #0");
  230.   ol("bne *+5");
  231.   ot("jmp ");
  232.   printlabel(label);
  233.   nl();
  234.   }
  235.  
  236. /*** test primary register against zero and jump if false*/
  237. /*    Mod 3/25/87 Test for false & jmp if condition
  238.     is met    jrd    */
  239. zerojump(oper, label, lval) int oper, label, lval[]; {
  240.   ol("cmpd #0");
  241.   ol("bne *+5");
  242.   ot("jmp ");
  243.   printlabel(label);
  244.   nl();
  245.   }
  246.  
  247. /*** define storage according to size*/
  248. defstorage(size) int size; {
  249.   if(size==1) ot("fcb ");
  250.   else          ot("fdb ");
  251.   }
  252.  
  253. /*** point to following object(s)*/
  254. point() {
  255.   ol("fdb $+2");
  256.   }
  257.  
  258. /*** modify stack pointer to value given*/
  259. modstk(newsp, save)  int newsp, save; {
  260.   int k;
  261.   k=newsp-csp;
  262.   if(k==0)return newsp;
  263.   if(k>=0) {
  264.     if(k<12) {
  265.       if(k&1) {
  266.     ol("ins");
  267.     k--;
  268.     }
  269.       while(k) {
  270.     ol("pulx");
  271.     k=k-BPW;
  272.     }
  273.       return newsp;
  274.       }
  275.     }
  276.   if(k<0) {
  277.     if(k>-7) {
  278.       if(k&1) {
  279.     ol("des");
  280.     k++;
  281.     }
  282.       while(k) {
  283.     ol("pshx");
  284.     k=k+BPW;
  285.     }
  286.       return newsp;
  287.       }
  288.     }
  289.   if(save) swap();
  290. ol("tsx");
  291. ol("pshx");
  292. const1(k);
  293. ol("tsx");
  294. ol("addd 0,x");
  295. ol("pulx");
  296. ol("txs");
  297.   if(save) swap();
  298.   return newsp;
  299.   }
  300.  
  301. /*** double primary register*/
  302. doublereg()
  303. { ol("asld");
  304. }
  305.